package com.hl.card.modular.packBack.service.impl;

import com.hl.card.common.persistence.dao.DisMemberInfoMapper;
import com.hl.card.common.persistence.model.DisMemberInfo;
import com.hl.card.common.util.FileUtil;
import com.hl.card.modular.packBack.model.ExcelPartnerList;
import com.hl.card.modular.packBack.service.PartnerListService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class PartnerListServiceImpl implements PartnerListService{

    @Resource(name = "disMemberInfoMapper")
    private DisMemberInfoMapper disMemberInfoMapper;

    @Override
    public List<DisMemberInfo> selectList(Map<String, Object> map) {
        List<DisMemberInfo> list = disMemberInfoMapper.selectPartner(map);
        return list;
    }

    @Override
    public void delete(int id) {
        disMemberInfoMapper.deleteById(id);
    }

    @Override
    public void update(DisMemberInfo disMemberInfo) {
        disMemberInfoMapper.updateById(disMemberInfo);
    }

    @Override
    public DisMemberInfo selectById(Integer id) {
        DisMemberInfo disMemberInfo = disMemberInfoMapper.selectByPartnerId(id);
        return  disMemberInfo;
    }

    @Override
    public void stopUse(Integer id) {
        disMemberInfoMapper.stopUse(id);
    }

    @Override
    public void use(DisMemberInfo disMemberInfo) {
        disMemberInfoMapper.use(disMemberInfo);
    }

    @Override
    public void excelList(Map<String, Object> map,HttpServletResponse response) throws Exception {
        List<DisMemberInfo> list =  disMemberInfoMapper.selectPartnerExcel(map);

        List<ExcelPartnerList> result = new ArrayList<>();
        for (int i =0;i < list.size();i++){
            DisMemberInfo disMemberInfo = list.get(i);

            ExcelPartnerList excelPartnerList = new ExcelPartnerList();
            excelPartnerList.setDisUserId(disMemberInfo.getDisUserId());
            excelPartnerList.setZhuangtai(disMemberInfo.getZhuangtai());
            excelPartnerList.setDisUserName(disMemberInfo.getDisUserName());
            excelPartnerList.setBinding_phone(disMemberInfo.getBinding_phone());
            excelPartnerList.setDis_recommendation_no(disMemberInfo.getDis_recommendation_no());
            excelPartnerList.setIdNo(disMemberInfo.getIdNo());
            excelPartnerList.setBinding_email(disMemberInfo.getBinding_email());
            excelPartnerList.setDis_member_time(disMemberInfo.getDis_member_time());
            excelPartnerList.setStupUse_time(disMemberInfo.getStupUse_time());
            result.add(excelPartnerList);
        }
        FileUtil.exportExcel(result, "合伙人列表", "酒店", ExcelPartnerList.class, "合伙人列表.xls",response);
    }
}
